﻿using BaseUtils.Logger;
using Newtonsoft.Json;
using Service.src.Model.Folw;
using Service.src.NW.Model.Enum;
using System;
using System.Diagnostics;

namespace Service.src.NW.Model.Folw
{
    public class RuntimeParam : FlowNode
    {

        /// <summary>
        /// 流程 ID
        /// 运行时使用，不用持久化
        /// </summary>
        [JsonIgnore]
        public long _FlowId { get; set; }

        [JsonIgnore]
        public Stopwatch stopwatch = new Stopwatch();

        /// <summary>
        /// 脚本节点参数，在编译时修改为 true
        /// </summary>
        [JsonIgnore]
        public bool IsPreCompiling = false;

        /// <summary>
        /// JsonIgnore 保存时忽略
        /// 耗时统计
        /// </summary>
        public double NodeTotalSeconds { get; set; }

        // JsonIgnore 保存时忽略
        public NodeLogger Logger { get; set; }

        /// <summary>
        /// JsonIgnore 保存时忽略
        /// </summary>
        public int Code { get; set; } = 1;

    }

    public class NodeLogger
    {
        public ExceptionLevelEnum Level { get; set; }

        public string Time { get; set; }

        public string Message { get; set; }

        public double TotalSeconds { get; set; }
        public int NodeId { get; set; }
        public int Code { get; set; }

        public NodeLogger()
        {

        }

        public NodeLogger(string Msg)
        {
            Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
            Message = Msg;
            Level = ExceptionLevelEnum.Default;
            //LoggerService.Info(Msg);
        }

        public NodeLogger Info(ExceptionLevelEnum _level = ExceptionLevelEnum.Info) {
            Level = _level;
            LoggerService.Info(this.Message);
            return this;
        }

        public NodeLogger Error(Exception ex = null)
        {
            Level = ExceptionLevelEnum.Error;
            LoggerService.Error(this.Message, ex);
            return this;
        }

        public NodeLogger Warning()
        {
            Level = ExceptionLevelEnum.Warning;
            LoggerService.Warning(this.Message);
            return this;
        }
    }
}
